// Inventive hints (directives to specify lack of inventiness reasoning) 

//  id              Desc                          EPC   #docs  Strat
//-------------------------------------------------------------------
//  normal     normal design option               E02A    2      XA
//  obvious    obvious combination                E02B    1      X
//  choice     mere choice                        E02C    1      X
//  equiv      replacing a feature by equivalent  E02D    1      X    
//  combi      features known from combination    E02E    2      XA, YY
//  known      well known in the art              E03C    1      X, XA
//  1->N       generalization                             1      X
//  detail     implementation detail                      1      X

//var INV_HINTS     =new Array("choice","known","combi","equiv","normal","1->N","detail");

//var INV_HINTS     = getMenuH();


 
// Fast inv hint check
var RINV_HINTS = [];

var PRS_HINTS=["implicit","ignore"];
var RPRS_HINTS=new Array();
RPRS_HINTS["ignore"]  =1;
RPRS_HINTS["implicit"]=1;

var RIGN_HINTS=new Array();
RIGN_HINTS["ignore"]  =1;

var GLUE_HINT="---- + ----";
var GLUE_HINTS=[GLUE_HINT];
var RGLUE_HINTS=new Array();
RGLUE_HINTS[GLUE_HINT]=1;
RGLUE_HINTS["--------"]=1;

var SKIP_HINTS=["skip"];
var RSKIP_HINTS=new Array();
RSKIP_HINTS["skip"] = 1;

// number of parameters for hints (0,1)
var RPAR_HINTS= new Array();
RPAR_HINTS["equiv"]=1;
RPAR_HINTS["implicit"]=1;

var ALL_HINTS;
var ALLBDOCS;
var ALL_RHINTS;

// get list of inventive objections
function getInvObjs() {
  return ALLBDOCS;
}

function rebuild_hints() {
  ALLBDOCS=getMenuH(); // B docs map into inv hints
  ALL_HDOCS=([""]).concat(ALLBDOCS);
  ALL_HINTS=([""]).concat(ALLBDOCS).concat(GLUE_HINTS).concat(PRS_HINTS).concat(SKIP_HINTS);
  ALL_RHINTS=[];  
  for(var e in ALLBDOCS) {  // build inventive hints array from ALLBDOCS set
    RINV_HINTS[ALLBDOCS[e]]=1;
  }
  RINV_HINTS["combi"]   =2; // combi needs 2 docs
  for(var e in ALL_HINTS) {
    ALL_RHINTS[ALL_HINTS[e]]=1;
  }
  InitDocPNB();
}

rebuild_hints();


function hint_selection(id,val,callback,opt) {
  return html_selection(id,ALL_HDOCS,val,callback,opt);
}

function hint_doselect(id,val) {
  html_doselect(id,"",val);
}

// return how many docs are necessary for this hint to work
function getHintNeeds(hint) {
  return RINV_HINTS[hint] || 0;
}  

// is hint related to inventive step
function is_invhint(hint) {  
  return RINV_HINTS[hint]; // hint && RINV_HINTS[hint];
}

// hints that strip feature out
function is_skip_hint(hint) {
  return RSKIP_HINTS[hint];
}

// hints that specify that feature is present 
function is_present_hint(hint) {
  return RPRS_HINTS[hint];
}

// check if hint uses params
function is_param_hint(hint) {
  return (hint && RPAR_HINTS[hint]) || 0;
}

// not real hint
function is_ignore_hint(hint) {
  return RIGN_HINTS[hint];
}

// not real hint
function is_glue_hint(hint) {
  return RGLUE_HINTS[hint];
}

// not glue hint
function is_notglue_hint(hint) {
  return hint && !RGLUE_HINTS[hint];
}

// hint does not imply feature is present
function is_notpresent_hint(hint) {
  return hint && RINV_HINTS[hint]; // && !RPRS_HINTS[hint] && !RSKIP_HINTS[hint]; // hint && RINV_HINTS[hint];
}

// is hint 
function is_B_hint(doc) {
  return ALL_RHINTS[doc];
}

// return true if B is a doc or a inv hint no present.
function is_B_empty(doc) {
  return !doc || !RINV_HINTS[doc];
}

// merge two hints 
function hint_join(h1,h2) {
  if( h1 && RINV_HINTS[h1]) {
    return h1;
  }
  return h2;
}

// When hint changes, novelty/inventiveness may change
// pick first (inv) hint in claim as document B if no real document B is selected.
// put it in hint field so lack of inventive step can be easily checked
// do it only if pn is X document for cl

function update_B_hints(cl) {
  var pn=GetClaimDoc_X(cl);

  if(!pn) {
    SetClaimHint(cl,"");
    return;
  }

  var tf_iter= new claim_features_iterator(cl);
  var hint="";
  var usehint="";
  
  while(!tf_iter.end()) {
    hint=GetPassageHintEq(cl,tf_iter.getValue(),pn);  
    if(is_invhint(hint)) {
      //alert("Use hint "+hint);
      usehint=hint;
      break; // find first hint
    };
    tf_iter.next();
  }
  //alert("update_B_hints("+cl+","+pn+")=>Set B to "+usehint);
  SetClaimHint(cl,usehint); //usehint);          
}


// Collect inventive objections in technical features

function xxx_dohints(clist,law) {
  var cl_iter=new List_iterator(clist);
  var notinv=[];
  var invxmlobjs=[];
  var ignacc="",ref;
  var html="";

  for(var invidx in ALLBDOCS) {
    invxmlobjs[ALLBDOCS[invidx]]= new objectiondict();
  }

  while(!cl_iter.end()) {
    var cl=cl_iter.getValue();    
    if(IsClaimNotInventive(cl)) {
      var pn=GetClaimDoc_X(cl);
      notinv.push(cl);
      // check tech features for clarity objections
      var tf_iter= new claim_features_iterator(cl);
      while(!tf_iter.end()) {
	var tfxt=partrim(tf_iter.getDesc());  // get rid of applicants references  
	var hint=tf_iter.getHint(pn);
	if(!is_skip_hint(hint)) { // skip this feature
	  if(is_glue_hint(hint)) {
	    ignacc+=tfxt+" "; // glue together splitted text
	  } else {
	    var ref =trim(tf_iter.getPassageEqIgn(pn))|| "";
	    var hint=tf_iter.getHintEqIgn(pn);
	    tfxt=ignacc+tfxt;
	    ignacc="";	
	    if(!(is_present_hint(hint) || (ref && !is_notpresent_hint(hint)))) { 
	      invxmlobjs[hint].add(cl,tfxt);
	    }
	  }
	} 
	tf_iter.next();
      }
    }
    cl_iter.next();
  }  
  
  // render inventive objections
  if(notinv.length()) { 
    html+=stdcls_apply_inv("header",notinv,law)+BR2;
    for(var invidx in ALLBDOCS) {
      var hint =ALLBDOCS[invidx];
      if(invxmlobjs[hint]) {
	if(invxmlobjs[hint].length()) {
	  html+=stdcls_apply_hint(hint,invxmlobjs[hint],law)+BR2;
	}
      }
    }
  }    
  return html;
}



